﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chefbook.DataObjects;
using System.Globalization;
using Chefbook.ViewModels;

namespace Chefbook.UserActions
{
    /// <summary>
    /// An action for moving a recipe from one category to another
    /// </summary>
    public class MoveRecipeAction : UserActionBase
    {
        private RecipeViewModel recipeToMove;
        private CategoryViewModel fromCategory, toCategory;

        /// <summary>
        /// Creates a new action to move a recipe from one category to another
        /// </summary>
        /// <param name="recipeToMove">The recipe to move</param>
        /// <param name="fromCategory">The category to move from</param>
        /// <param name="toCategory">The category to move to</param>
        public MoveRecipeAction(RecipeViewModel recipeToMove, CategoryViewModel fromCategory, CategoryViewModel toCategory)
            : base()
        {
            this.recipeToMove = recipeToMove;
            this.fromCategory = fromCategory;
            this.toCategory = toCategory;
        }

        /// <summary>
        /// Moves the recipe to the new category
        /// </summary>
        public override void DoAction()
        {
            base.DoAction();
            recipeToMove.RecipeModel.ChangeCategory(fromCategory.CategoryModel, toCategory.CategoryModel);
        }

        /// <summary>
        /// Returns the recipe to the old category
        /// </summary>
        public override void UndoAction()
        {
            base.UndoAction();
            recipeToMove.RecipeModel.ChangeCategory(toCategory.CategoryModel, fromCategory.CategoryModel);
        }

        /// <summary>
        /// Returns a user-friendly string describing the action
        /// </summary>
        /// <returns>A user-friendly string describing the action</returns>
        public override string ToString()
        {
            return string.Format(CultureInfo.CurrentUICulture, "Move Recipe '{0}' from '{1}' to '{2}'", recipeToMove, fromCategory, toCategory);
        }
    }
}
